package knapsackProblem;
public class Item implements Comparable<Item> {

	public Item(int profit, long time) {
		this.profit = profit;
		this.time = time;
	}

	public Item(Item item) {
		this.profit = item.profit;
		this.time = item.time;
	}

	public void setProfit(int profit) {
		this.profit = profit;
	}

	public void setTime(long time) {
		this.time = time;
	}

	protected int profit;
	protected long time;

	public int getProfit() {
		return profit;
	}

	public long getTime() {
		return time;
	}

	public int compareTo(Item item) {
		float comparsion = item.time == 0 && this.time == 0 ? item.profit
				- this.profit : getProfitToTime(item) - getProfitToTime(this);
		int com = (comparsion == 0) ? 0 : (comparsion > 0) ? 1 : -1;
		return com;
	}

	public static float getProfitToTime(Item item) {
		if (item.time == 0)
			return item.profit > 0 ? Float.POSITIVE_INFINITY
					: Float.NEGATIVE_INFINITY;
		return (float) item.profit / (float) item.time;
	}
}